package com.example.dell.fastshopping.DuoBao;

import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.dell.fastshopping.DuoBao.model.DuoBaoActViewModel;
import com.example.dell.fastshopping.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by ${YSH} on 2019/5/1.
 * 描述        ${TODO}
 * <p>
 * 更新者       $author$
 * 更新时间     $Data$
 * 描述         ${TODO}
 */
public class GoodsIntroduceFragment extends Fragment {

    @BindView(R.id.introduce)
    TextView introduce;
    private DuoBaoActViewModel model;
    private Unbinder bind;

    public static GoodsIntroduceFragment newInstance() {
        return new GoodsIntroduceFragment();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_goods_introduce, container, false);
        bind = ButterKnife.bind(this, inflate);
        return inflate;

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        bind.unbind();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        model = ViewModelProviders.of(getActivity()).get(DuoBaoActViewModel.class);
        model.getGoodInfo().observe(this, new Observer<String>() {
            @Override
            public void onChanged(@Nullable String s) {
                introduce.setText("商品简介："+s);
            }
        });
    }
}
